package com.guli.product.exception;

import com.guli.common.response.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice//Aop
public class ProductExeptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共异常处理类");
        return new Result(false,"0000",
                e.getClass()
                .getName()+"==>"+
                e.getMessage());
    }
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result runtime(Exception e){
        e.printStackTrace();
        System.out.println("调用了运行时异常公共异常处理类");
        return new Result(false,"0001",
                e.getClass().getName() +"==>" + e.getMessage());
    }
    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result sql(Exception e){
        e.printStackTrace();
        System.out.println("调用了sql异常公共异常处理类");
        return new Result(false,"0002",
                e.getClass().getName()+"==>"+
                e.getMessage());
    }




}
